//
//  Login.swift
//  DesignCode
//
//  Created by 李澄 on 2020/11/18.
//  Copyright © 2020 Mithun. All rights reserved.
//

import SwiftUI

struct Login: View {
    @State var account: String = ""
    @State var password: String = ""
    @State var showPwd = false
    @State var showHome = false
    var canLogin: Bool {
        account.count > 0 && password.count > 0
    }
    var body: some View {
        VStack(spacing: 40) {
            Image("Certificate2")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(height: 200)
            
            VStack(spacing: 20) {
                HStack {
                    Image(systemName: "person")
                    TextField("请输入账号", text: $account, onCommit: {
                        
                    })
                }
                Divider()
                HStack {
                    Image(systemName: "lock")
                    if showPwd {
                        TextField("请输入密码", text: $password, onCommit: {
                           
                        })
                    } else {
                        SecureField("请输入密码", text: $password, onCommit: {
                            
                        })
                    }
                    Button(action: {
                        self.showPwd.toggle()
                    }) {
                        Image(systemName: showPwd ? "eye": "eye.slash")
                    }
                }
                Divider()
            }
//                NavigationLink(
//                    destination: Home(), tag: 1, selection: $showHome) {
//                    Button(action: {
//                        self.showHome = 1
//                    }) {
//                        Text("登录")
//                            .foregroundColor(.white)
//                    }
//                    .frame(width: 100, height: 45, alignment: .center)
//                    .background(canLogin ? Color.blue: Color.gray)
//                    .cornerRadius(10)
//                    .disabled(!canLogin)
//
//
//                }
            Button(action: { self.showHome.toggle() }) {
                Text("登录")
                    .frame(width: 100, height: 50, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                    .background(Color("button"))
                    .cornerRadius(30)
                    .shadow(color: Color("buttonShadow"), radius: 20, x: 0, y: 20)
                    .sheet(isPresented: self.$showHome) { Home()}
                    
            }
            Spacer()
        }
        .padding(.top, 100)
        .padding(.leading)
        .padding(.trailing)
        
    }
}

struct Login_Previews: PreviewProvider {
    static var previews: some View {
        Login()
    }
}
